package vn.gq.tym.tonghopvf;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class ReaderSettings {
	
	public static final String PREF_NAME = "pref_settings";
	public static final String PREF_FONT_SIZE = "reader_font_size";
	public static final String PREF_NIGHT_MODE = "reader_night_mode";
	
	private Context context;
	
	public static ReaderSettings getInstance(Context context) {
		ReaderSettings settings = new ReaderSettings(context);
		return settings;
	}
	
	public ReaderSettings(Context context) {
		this.context = context;
	}
	
	public int getFontSize(int defaultSize) {
		SharedPreferences sharePref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		int size = sharePref.getInt(PREF_FONT_SIZE, defaultSize);
		return size;
	}
	
	public void setFontSize(int value) {
		SharedPreferences sharePref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		Editor editor = sharePref.edit();
		editor.putInt(PREF_FONT_SIZE, value);
		editor.commit();
	}
	
	public boolean isNightMode() {
		boolean val = false;
		try {
			SharedPreferences sharePref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
			val = sharePref.getBoolean(PREF_NIGHT_MODE, false);
		} catch(NullPointerException e) {
		}
		return val;
	}
	
	public void setNightMode(boolean val) {
		SharedPreferences sharePref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		Editor editor = sharePref.edit();
		editor.putBoolean(PREF_NIGHT_MODE, val);
		editor.commit();
	}

}
